home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / ThreadLibrary-1.0 / Interfaces / ThreadLibrary.h next >
Text File  |  1995-06-08  |  5KB  |  158 lines

  1. /* See the file Distribution for distribution terms.
  2.     (c) Copyright 1994-1995 Ari Halberstadt */
  3.  
  4. #pragma once
  5. #ifndef THREAD_LIBRARY
  6. #define THREAD_LIBRARY
  7.  
  8. #include <limits.h>
  9. #include <stddef.h>
  10. #include <Types.h>
  11.  
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15.  
  16. #define THREAD_VERSION        (0x0100)        /* version of thread library */
  17. #define THREAD_SIZE_MAX        (LONG_MAX)    /* maximum size of a pointer */
  18. #define THREAD_TICKS_MAX    (LONG_MAX)    /* maximum number of ticks */
  19. #define THREAD_TICKS_SEC    (60L)            /* number of ticks in a second */
  20. #define THREAD_NONE            (0)            /* serial number of an invalid thread */
  21.  
  22. /* memory types */
  23. typedef unsigned long ThreadTypeType;
  24. enum {
  25.     THREAD_TYPE_NONE            = 0,
  26.     THREAD_TYPE_FREE            = 'free',    /* free memory */
  27.     THREAD_TYPE_ALLOC            = 'aloc',    /* allocated memory */
  28.     THREAD_TYPE_UNSPECIFIED    = 'unsp',    /* unspecified memory type */
  29.     THREAD_TYPE_THREAD        = 'thrd',    /* memory for private thread structure */
  30.     THREAD_TYPE_STACK            = 'stak',    /* memory for stack */
  31.     THREAD_TYPE_LAST
  32. };
  33.  
  34. /* error numbers */
  35. typedef OSErr ThreadErrorType;
  36. enum {
  37.     THREAD_ERROR_NONE            = 0,            /* no error */
  38.     THREAD_ERROR_NOT_FOUND    = -618,        /* thread not found (threadNotFoundErr) */
  39.     THREAD_ERROR_PROTOCOL    = -619,        /* error in protocol (threadProtocolErr) */
  40.     THREAD_ERROR_LAST
  41. };
  42.  
  43. /* thread types */
  44.  
  45. typedef Ptr ThreadStackPtr;                /* pointer into a thread's stack */
  46. typedef long ThreadType;                    /* thread reference */
  47. typedef long ThreadTicksType;                /* clock ticks */
  48. typedef long ThreadSizeType;                /* size of a pointer */
  49. typedef void *ThreadDataType;                /* application defined data */
  50.  
  51. /* scheduler callback function */
  52. typedef ThreadType (*ThreadProcScheduleType)(ThreadType suggested);
  53.  
  54. /* memory allocation callback function */
  55. typedef void *(*ThreadProcAllocateType)(ThreadSizeType size, ThreadTypeType type);
  56.  
  57. /* memory disposal callback function */
  58. typedef void (*ThreadProcDisposeType)(void *p,  ThreadSizeType size,
  59.     ThreadTypeType type);
  60.  
  61. /* thread resume, suspend, and entry callback functions */
  62. typedef void (*ThreadProcType)(ThreadDataType data);
  63.  
  64. /* thread begin/end callback functions */
  65. typedef void (*ThreadProcBeginEndType)(ThreadType thread, ThreadDataType data);
  66.  
  67. #if THREAD_OBSOLETE
  68.     /* The type ThreadSNType is a synonym for the type ThreadType.
  69.         Applications should refer to threads using variables of type
  70.         ThreadType. The type ThreadSNType is included for compatability
  71.         with versions 1.0d2.2 through 1.0d3. New applications should no
  72.         longer use the type ThreadSNType. The same applies to
  73.         THREAD_SN_NONE. */
  74.     #define THREAD_SN_NONE THREAD_NONE
  75.     typedef ThreadType ThreadSNType;
  76. #endif /* THREAD_OBSOLETE */
  77.  
  78. ThreadErrorType ThreadError(void);
  79. void ThreadErrorSet(ThreadErrorType error);
  80.  
  81. long ThreadCount(void);
  82. ThreadType ThreadMain(void);
  83. ThreadType ThreadActive(void);
  84. ThreadType ThreadFirst(void);
  85. ThreadType ThreadNext(ThreadType thread);
  86.  
  87. Boolean ThreadExists(ThreadType thread);
  88.  
  89. ThreadDataType ThreadData(ThreadType thread);
  90. void ThreadDataSet(ThreadType thread, ThreadDataType data);
  91.  
  92. ThreadProcScheduleType ThreadProcSchedule(void);
  93. void ThreadProcScheduleSet(ThreadProcScheduleType schedule);
  94.  
  95. ThreadProcAllocateType ThreadProcAllocate(void);
  96. void ThreadProcAllocateSet(ThreadProcAllocateType allocate);
  97.  
  98. ThreadProcDisposeType ThreadProcDispose(void);
  99. void ThreadProcDisposeSet(ThreadProcDisposeType dispose);
  100.  
  101. ThreadProcBeginEndType ThreadProcBegin(ThreadType thread);
  102. void ThreadProcBeginSet(ThreadType thread, ThreadProcBeginEndType begin);
  103.  
  104. ThreadProcBeginEndType ThreadProcEnd(ThreadType thread);
  105. void ThreadProcEndSet(ThreadType thread, ThreadProcBeginEndType end);
  106.  
  107. ThreadProcType ThreadProcResume(ThreadType thread);
  108. void ThreadProcResumeSet(ThreadType thread, ThreadProcType resume);
  109.  
  110. ThreadProcType ThreadProcSuspend(ThreadType thread);
  111. void ThreadProcSuspendSet(ThreadType thread, ThreadProcType suspend);
  112.  
  113. ThreadProcType ThreadProcEntry(ThreadType thread);
  114. void ThreadProcEntrySet(ThreadType thread, ThreadProcType entry);
  115.  
  116. ThreadSizeType ThreadStackMinimum(void);
  117. ThreadSizeType ThreadStackDefault(void);
  118. ThreadSizeType ThreadStackSize(ThreadType thread);
  119. ThreadSizeType ThreadStackSpace(ThreadType thread);
  120.  
  121. ThreadStackPtr ThreadStackFramePointer(ThreadType thread);
  122.  
  123. Boolean ThreadEnabled(ThreadType thread);
  124. void ThreadEnabledSet(ThreadType thread, Boolean enabled);
  125.  
  126. ThreadTicksType ThreadWakeTime(ThreadType thread);
  127. void ThreadWakeTimeSet(ThreadType thread, ThreadTicksType wake);
  128.  
  129. void ThreadSleepSet(ThreadType thread, ThreadTicksType sleep);
  130. void ThreadSleepIntervalSet(ThreadType thread, ThreadTicksType sleep);
  131.  
  132. ThreadType ThreadSchedule(void);
  133.  
  134. void ThreadActivate(ThreadType thread);
  135. void ThreadYield(ThreadTicksType sleep);
  136. ThreadTicksType ThreadYieldInterval(void);
  137.  
  138. ThreadType ThreadBeginMain(
  139.     ThreadProcType suspend,
  140.     ThreadProcType resume,
  141.     ThreadDataType data);
  142.  
  143. ThreadType ThreadBegin(
  144.     ThreadProcType entry,
  145.     ThreadProcType suspend,
  146.     ThreadProcType resume,
  147.     ThreadDataType data,
  148.     ThreadSizeType stack_size);
  149.  
  150. void ThreadEnd(ThreadType thread);
  151. void ThreadEndAll(void);
  152.  
  153. #ifdef __cplusplus
  154. }
  155. #endif
  156.  
  157. #endif /* THREAD_LIBRARY */
  158.